package com.example.demo.service.impl;

import com.example.demo.mapper.EnvMapper;
import com.example.demo.entity.Env;
import com.example.demo.service.EnvService;
import com.example.demo.utils.DateToStamp;
import com.example.demo.utils.PageInfoNew;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EnvServiceImpl implements EnvService {

    @Resource
    EnvMapper envMapper;

    @Override
    public void insert(Env env) {
        env.setCreateTime(DateToStamp.getTimeStamp());
        env.setUpdateTime(DateToStamp.getTimeStamp());
        envMapper.insert(env);
    }

    @Override
    public PageInfoNew<Env> selectByProjectId(int pageNum, int pageSize, int projectId) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfoNew<>(envMapper.selectByProjectId(projectId));
    }

    @Override
    public List<Env> selectByProjectIdForList(int projectId) {
        return envMapper.selectByProjectId(projectId);
    }

    @Override
    public Env selectById(int id) {
        return envMapper.selectById(id);
    }

    @Override
    public void updateEnv(Env env) {
        env.setUpdateTime(DateToStamp.getTimeStamp());
        envMapper.updateEnv(env);
    }

    @Override
    public void deleteEnv(int id) {
        envMapper.deleteEnv(id);
    }
}
